<template>
	<view>
		<Header title="余额明细" :isHome="true" :isWhite="true"></Header>
		<view class="tabs">
			<view class="discipline">
				<view class="discipline-detail" :class="{ 'discipline-detail-active': activeIndex === index }"
					v-for="(item, index) in discipline" :key="index" @click="changeTab(index)">
					{{ item.name }}
				</view>
			</view>
		</view>
		<view class="cards">
			<view class="card" v-for="item in list" :key="item.id">
				<view class="left">
					<p>{{ item.statename }}</p>
					<text>{{ item.createtime}}</text>
				</view>
				<view class="rig">
					<span :class="{ positive: isPositive(item.money) }">{{item.money}}</span>
				</view>
			</view>
		</view>
		<view class="more">没有更多了</view>
	</view>
</template>
<script>
	import {
		get,
		post
	} from '../../utils/request';
	export default {
		data() {
			return {
				page: 1,
				activeIndex: 0,
				discipline: [{
						name: "全部",
					},
					{
						name: "收入",
					},
					{
						name: "支出",
					},
				],
				list: [],
			};
		},
		onLoad() {
			this.page = 0
			this.getMoneyLog()
		},
		onReachBottom() {
			this.page++
			this.getMoneyLog()
		},
		methods: {
			getMoneyLog() {
				get('/user/get_money_log?type=' + this.activeIndex + '&page=' + this.page)
					.then(res => {
						if (this.page == 0) {
							this.list = res.data.data
						} else {
							this.list = this.list.concat(res.data.data)
						}
					})
					.catch(err => {
						console.error('GET 请求失败:', err);
					});
			},
			isPositive(price) {
				// 清除所有非数字字符（包括符号），然后转换成浮点数进行比较
				return parseFloat(price.replace(/[^\d.-]/g, "")) > 0;
			},
			changeTab(index) {
				console.log(index);
				this.activeIndex = index;
				this.getMoneyLog()
			}
		}
	};
</script>
<style lang='scss' scoped>
	.positive {
		color: #fb2f47;
		font-weight: 600;
		font-size: 32rpx;
	}

	.more {
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		text-align: center;
	}

	.rig {
		font-weight: 600;
		font-size: 32rpx;
		color: #1a1a1a;
	}

	.left {
		p {
			font-weight: 600;
			font-size: 32rpx;
			color: #222222;
			margin-bottom: 8rpx;
		}

		text {
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
		}
	}

	.card {
		background: #f0f0f0;
		border: 3rpx solid #dddddd;
		border-radius: 12rpx;
		padding: 32rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.cards {
		margin: 32rpx;
	}

	.tabs {
		background: #fff;
		width: 100%;
		padding: 10rpx 0;
		display: flex;
		justify-content: center;
	}

	.discipline {
		display: flex;
		justify-content: space-around;
		align-items: center;
		width: 362rpx;
		height: 64rpx;
		border: 3rpx solid #1a1a1a;
		border-radius: 12rpx;
		margin: 20rpx 0;
	}

	.discipline-detail {
		font-family: PingFangSC-SNaNrpxibold;
		font-weight: 600;
		font-size: 26rpx;
		color: #222222;
		width: 110rpx;
		height: 48rpx;
		text-align: center;
		line-height: 48rpx;
	}

	.discipline-detail-active {
		font-family: PingFangSC-SNaNrpxibold;
		font-weight: 600;
		font-size: 26rpx;
		color: #fff;
		background: url(/static/active-bg.png) no-repeat center center / cover;
	}
</style>